<template>
    <div class="TopFive">
        <el-table
            height="100%"
            :header-cell-style="{
                background:'rgb(2, 16, 51)',
                color:'aliceblue',
                border:'0px',
                'text-align':'center',
                padding:'0px 0px 0px 0px',
                'box-shadow': '0px 0px 30px  rgb(1, 40, 107) inset'}"
            :cell-style="{
                background:'rgb(2, 16, 51)',
                color:'aliceblue',
                border:'1px solid rgb(4, 44, 119)',
                'border-right':'0px',
                'border-left':'0px',
                'text-align':'center',
                padding:'0 0 0 0'}"
            :data="tableData"
            style="width: 100%" >
            <el-table-column
                type="index"
                width="20">
            </el-table-column>
                <template v-for="(item) in tableColumns">
                <el-table-column
                    :prop="item.prop"
                    :label="item.label"
                    align="center"
                    :width="item.width"
                    :key="item.prop">
                </el-table-column>
            </template>
        </el-table>
    </div>
</template>

<script>
import { fetchData } from '@/api/index.js';
import bus from 'common/bus.js';
import tableColumns from './TopFiveTableColumns.js'

export default {
    data() {
        return {
            postData: {
                opera: 'DBTopWaits',
                curPage: 1,
                pageSize: 5,
                sort: {
                    sortColumn: 'pctdbtime',
                    sortOrders: 'desc'
                },
                filtersType: 'fuzzyquery',
                filters: {
                    "monid":""
                },
            },
            tableData: [],
            tableColumns: tableColumns,
            timerName: 'AlarmLog',
            timerEventName: 'timerAlarmLog',
            timerInterval: 1000 * 60,
            selectedMonID: {}
        }
    },
    created() {
        // this.getData();
        
        bus.$on('selectedMonID', msg => {
            this.selectedMonID = msg;
            this.postData.filters.monid = this.selectedMonID.selectedDBMonID;
            this.getData();
        });
        
        bus.$emit('timerNewTodo', {
            name: this.timerName,
            eventName: this.timerEventName,
            interval: this.timerInterval,
            intervalNow: 0
        });

        bus.$on(this.timerEventName, msg => {
            if (msg.isGetData) {
                this.getData();
            }
        });
        
    },
    mounted() {

    },
    computed: {
        postDataFn() {
            return {
                postData : JSON.stringify(this.postData)
            }
        }
    },
    methods: {
        getData(){
            fetchData(
                this.postDataFn
            ).then((res) => {
                if (res.data.length == 0) {
                    this.tableData = [];
                }else{
                    for (let i = 0; i <= res.data.length; i++) {
                        this.tableData = res.data;
                    };
                }
            });
        }
    },
    beforeDestroy() {
        bus.$emit('timerNewTodo', {
            name: this.timerName
        });
    },
    watch:{
        
    }
}
</script>

<style scoped>
.TopFive{
    padding: 0px 5px;
    height: calc(100% - 22px - 8px);
    text-align: center;
    color: aliceblue;
}

/* 滚动条 */
.TopFive>>> .el-table--mini, .el-table--small, .el-table__expand-icon{
    background: rgb(2, 16, 51) !important;
}
.TopFive>>> .el-table::before{
    height: 0px !important;
}
.TopFive>>> .el-table th, .el-table tr{
    background-color: rgb(1, 40, 107);
}
.TopFive>>> .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; 
    height: 6px; 
}
.TopFive>>> .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: rgba(4, 44, 119, 0.7);
    border-radius: 3px;
}
</style>    